﻿using System;
using System.Collections.Generic;
using Abp.Runtime.Session;
using pandx.Mulan.DataImExPorting.Excel;
using pandx.Mulan.Dictionaries.Dto;
using pandx.Mulan.Dto;
using pandx.Mulan.Storage;

namespace pandx.Mulan.Dictionaries.Exporting
{
    public class DictionaryCategoryListExcelExporter:NpoiExcelExporterBase,IDictionaryCategoryListExcelExporter
    {
        private readonly IAbpSession _abpSession;

        public DictionaryCategoryListExcelExporter(IAbpSession abpSession, ITempFileCacheManager tempFileCacheManager) : base(
            tempFileCacheManager)
        {
            _abpSession = abpSession;
        }

        public FileDto ExportToExcel(List<DictionaryCategoryListDto> dictionaryCategoryListDtos)
        {
            return CreateExcelPackage("字典分类_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.CreateSheet("字典分类");
                    AddHeader(sheet,
                       
                        "创建时间",
                     
                        "分类代码",
                        "分类名",
                        "创建用户名",
                        "创建用户"
                    );
                    AddObjects(sheet,2,dictionaryCategoryListDtos,
                       
                        _=>_.CreationTime,
                    
                        _=>_.Code,
                        _=>_.Name,
                        _=>_.CreatorUserName,
                        _=>_.CreatorName
                    );
                    for(var i=1;i<=dictionaryCategoryListDtos.Count;i++)
                    {
                        sheet.AutoSizeColumn(i);
                    }
                });
        }
    }
}
